package com.it.travel.controller.admin;

import com.it.travel.common.RequiredPermission;
import com.it.travel.service.admin.AdminProductService;
import com.it.travel.vo.Params.PageParams;
import com.it.travel.vo.Params.admin.*;
import com.it.travel.vo.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/admin/product")
@CrossOrigin
public class AdminProductController {
    @Resource
    private AdminProductService adminProductService;

    /**
     * @param id 产品id
     * @return
     */
    @GetMapping("/getcategory")
    public Result<?> getCategoryIds(Integer id) {
        Result<?> result = adminProductService.getCategoryIds(id);
        return result;
    }

    @GetMapping("")
    public Result<?> getInfoPage(PageParams pageParams) {
        Result<?> result = adminProductService.getInfoPage(pageParams);
        return result;
    }

    @RequiredPermission("sys:product:add")
    @PostMapping("")
    public Result<?> save(@RequestBody AdminProductParams adminProductParams) {
//        System.out.println("adminProductParams = " + adminProductParams);
        Result<?> result = adminProductService.save(adminProductParams);
        return result;
//        return null;
//        return result;
    }

    @RequiredPermission("sys:product:delete")

    @DeleteMapping("/{id}")
    public Result<?> delete(@PathVariable("id") Integer id) {
        Result<?> result = adminProductService.delete(id);
        return result;
    }

    @RequiredPermission("sys:product:update")

    @PutMapping("")
    public Result<?> update(@RequestBody AdminProductSkuUpdateParams adminProductSkuUpdateParams) {
//        System.out.println("adminProductSkuUpdateParams = " + adminProductSkuUpdateParams);
        Result<?> result = adminProductService.update(adminProductSkuUpdateParams);
        return result;
//        return null;
    }

    @RequiredPermission("sys:product:delete")

    @PostMapping("/deletebatch")
    public Result<?> deletebatch(@RequestBody List<Integer> ids) {
        Result<?> result = adminProductService.deletebatch(ids);
        return result;
//        return null;
    }

    @RequiredPermission("sys:product:add")

    @PostMapping("/detail")
    public Result<?> saveProductDetail(@RequestBody AdminProductDetailParams adminProductDetailParams) {
        Result<?> result = adminProductService.saveProductDetail(adminProductDetailParams);
        return result;
//        return null;
    }

    @GetMapping("/detail/{id}")
    public Result<?> findProductDetail(@PathVariable("id") Integer id) {
        Result<?> result = adminProductService.findProductDetail(id);
        return result;
//        return null;
    }
//    @PutMapping("/detail")
//    public Result<?> updateProductDetail(@RequestBody AdminProductDeatilUpdateParams AdminProductDeatilUpdateParams ) {
//        Result<?> result = adminProductService.updateProductDetail(AdminProductDeatilUpdateParams);
//        return result;
//    }
}
